package com.easytouch.vmhdl.animation;

import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Created by a on 2017/9/29.
 */
public class AnimationUtils {

    /**
     * 旋转
     * @param imageView
     * @param time
     * @param fromDegrees
     * @param toDegrees
     * @param isReverse
     */
    public static void setrotateAnimation(ImageView imageView, long time, float fromDegrees, float toDegrees, boolean isReverse) {
        AnimationSet animationSet = new AnimationSet(true);
        RotateAnimation rotateAnimation = new RotateAnimation(fromDegrees, toDegrees, Animation.RELATIVE_TO_SELF,
                0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        rotateAnimation.setDuration(time);//设置动画持续时间
        rotateAnimation.setRepeatCount(-1);//设置重复次数
        rotateAnimation.setFillAfter(true);//动画执行完后是否停留在执行完的状态
        if (isReverse) {
            rotateAnimation.setRepeatMode(Animation.REVERSE);    //重新从头执行
        }
        animationSet.addAnimation(rotateAnimation);
        imageView.setAnimation(animationSet);

    }

    public static void setTranslateAnimation(TextView view) {
        AnimationSet animationSet = new AnimationSet(true);
        TranslateAnimation translateAnimation = new TranslateAnimation(0, 0, 0, 5);
        translateAnimation.setDuration(2000);
        translateAnimation.setRepeatCount(-1);               //设置重复次数
        translateAnimation.setRepeatMode(Animation.REVERSE);    //重新从头执行
        animationSet.addAnimation(translateAnimation);
        view.setAnimation(animationSet);
    }
}
